// 控制台输出带颜色
import clc from "cli-color";

// 2. 工具类打印日志
export class Logger {
  private static lastLogTime = Date.now();
  /**
   * 定义一个用来打印日志的工具方法
   * @param message 打印的信息
   * @param context 上下文（用于分类） 一般是类的名字
   */
  static log(message: string, context: string) {
    // 获取当前的时间戳
    const timestamp = new Date().toISOString();
    // 获取当前的进程ID
    const pid = process.pid;
    const currentTime = Date.now();
    console.log(
      `${clc.green("[Nest]")} ${clc.green(pid.toString())}  ${clc.green(
        "-"
      )} ${clc.yellow(timestamp)}     ${clc.green("LOG")} ${clc.yellow(
        `[${context}]`
      )} ${clc.green(message)} ${clc.red(currentTime - this.lastLogTime)}ms`
    );
    this.lastLogTime = currentTime;
  }
}
